﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Linq;
namespace WPFExcelReport
{
    public partial class TCWB14
    {


        public TCWB14()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_WBBEW();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 154)
                return;
            dwData = TBMain.NewRow();
            dwData["WBEWMANDANT"] = app.Mandant;
            dwData["WBEWLO"] = ORDERNUM.Substring(0, 2);
            dwData["WBEWLB"] = ORDERNUM.Substring(2, 2);
            dwData["WBEWBUCHDAT"] = ORDERNUM.Substring(4, 8);
            dwData["WBEWWAKZ"] = ORDERNUM.Substring(12, 1);
            dwData["WBEWART"] = ORDERNUM.Substring(13, 20);
            dwData["WBEWVAR"] = ORDERNUM.Substring(33, 2);
            dwData["WBEWFARBE"] = ORDERNUM.Substring(35, 10);
            dwData["WBEWBESCHICH"] = ORDERNUM.Substring(45, 10);
            dwData["WBEWDESS"] = ORDERNUM.Substring(55, 10);
            dwData["WBEWCOLORIT"] = ORDERNUM.Substring(65, 10);
            dwData["WBEWBS"] = ORDERNUM.Substring(152, 2);
            SResult = TMV.QWBBEW07(dwData);
            MergeData(SResult, false);
            base.LOADBYAUF();
        }

        public void WBWAdjustCommand(object sender, RoutedEventArgs e)
        {
            string RDATE="";
            if (dwMaster == null)
                return;
            if (!IsNew)
            {
                if (!IsEdit)
                {
                    INFO = "";
                }
                IsNew = true;
                IsEdit = true;
                dwData = TMV.STKG.TBMain.NewRow();
                RDATE=dwMaster["WBEWBUCHDAT"].ToString();
                  if(!INFO.Contains(RDATE+";"))
                    INFO+=RDATE+";";
                dwData["MDATE"] = dwMaster["WBEWBUCHDAT"];
                dwData["WAKZ"] = dwMaster["WBEWWAKZ"];
                dwData["LO"] = dwMaster["WBEWLO"];
                dwData["LB"] = dwMaster["WBEWLB"];
                TMV.STKG.DSTKG02(dwData);
               
                return;
            }

            TMV.UWBW02(dwMaster);

            TMV.VWBBEW.UTWBW04(dwMaster);

            dwData = TMV.STKG.TBMain.NewRow();

            dwData["MDATE"] = dwMaster["WBEWBUCHDAT"];
            RDATE = dwMaster["WBEWBUCHDAT"].ToString();
            if (!INFO.Contains(RDATE + ";"))
                INFO += RDATE + ";";

            dwData["WAKZ"] = dwMaster["WBEWWAKZ"];
            dwData["LO"] = dwMaster["WBEWLO"];
            dwData["LB"] = dwMaster["WBEWLB"];
            TMV.STKG.DSTKG02(dwData);
            IsNew = false;
            
        }

        private void DailyAdjustCommand(object sender, RoutedEventArgs e)
        {
            string[] dates = INFO.Split(';');
            foreach (string dat in dates)
            {
                TMV.STK.EXEDWI09(dat,1,"F");
            }
            INFO = ""; 
            IsEdit = false;
        }
    }
}
    